package com.zx.oa.controller;

import com.alibaba.fastjson.JSON;
import com.zx.oa.entity.Major;
import com.zx.oa.service.census.CensusService;
import com.zx.oa.service.census.CensusServicelpml;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/getmajor.do")
public class MoringMajorServelt extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        CensusService censusService=new CensusServicelpml();
        List<Major> majorList=censusService.getMajorAll();
        String jsonMajor = JSON.toJSONString(majorList);
        resp.setContentType("text/html;charset=utf-8");
        resp.setCharacterEncoding("UTF-8");
        PrintWriter out=resp.getWriter();
        out.print(jsonMajor);
        out.flush();
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
